package com.smarthome.domain.enums;

import java.util.HashMap;
import java.util.Map;

import com.smarthome.domain.mobile.MobileCodeEnum;

/**
 * @author dhc 短信异常定义一览表
 * @date 2015年10月16日 下午3:08:27
 * @title
 */
public enum SmsExceptionEnum {
	DEFAULT("SMS:0","未定义异常","未定义异常,获取返回值为 空"),
	ERROR("SMS:0000","短信发送出错","短信调用发送发送接口出现错误"),
	NUMBER_NOTTRUE("SMS:0001","发送号码不正确","发送号码不正确",MobileCodeEnum.SMS_SEND_EXCEPTION.getCustomEnum("发送号码不正确")),
	CONTENT_NULL("SMS:0002","发送内容为空","发送内容为空"),
	NULL("SMS:0003","短信存储对象为空","短信存储对象为空"),
	
	TEMPLET_NOTFIND("SMS:0004","短信模板为空","短信发送模板未找到，你可以 1、启用发送模板，2、新建发送模板"),
	TEMPLET_CONTENTNULL("SMS:0005","短信模板内容为空","短信模板那内容为空，你可以 1、编辑短信内容模板"),
	TYPE_ISNULL("SMS:0006","短信类型为空","短信类型为空。没有指定发送短信内容"),
	URID_ISNULL("SMS:0007","URID为空","URID为空。1、传入的URID 为空，2、未返回URID",MobileCodeEnum.SMS_SEND_EXCEPTION.getCustomEnum("id未传入")),
	CAPTCHA_ISNULL("SMS:0008","验证码为空","验证码为空。",MobileCodeEnum.SMS_SEND_EXCEPTION.getCustomEnum("验证码为空")),
	CAPTCHA_OVERTIEM("SMS:0009","验证超时","验证超时。",MobileCodeEnum.SMS_SEND_EXCEPTION.getCustomEnum("验证码超时")),
	;
	private String code;
	private String name;
	private String descript;
	private String number;
	private MobileCodeEnum codeEnum;

	private static Map<String,SmsExceptionEnum> map  = new HashMap<String,SmsExceptionEnum>();
	private SmsExceptionEnum(String code, String name,String descript) {
		this.code = code;
		this.name = name;
		this.descript = descript;
	}
	
	private SmsExceptionEnum(String code, String name,String descript,String number) {
		this.code = code;
		this.name = name;
		this.descript = descript;
		this.number = number;
		this.codeEnum = MobileCodeEnum.SMS_SEND_ERROR;
	}
	private SmsExceptionEnum(String code, String name,String descript,MobileCodeEnum codeEnum) {
		this.code = code;
		this.name = name;
		this.descript = descript;
		if(null == codeEnum) codeEnum = MobileCodeEnum.SMS_SEND_ERROR;
		this.codeEnum = codeEnum;
		
	}
	
	static{
		for(SmsExceptionEnum sms : SmsExceptionEnum.values()){
			map.put(sms.getCode(), sms);
		}
	}

	/** 
	 * @title 根据CODE返回数据,如无定义异常,返回默认异常
	 * @createTime 2015年10月15日 下午5:21:31
	 * @author dhc
	 */
	public static SmsExceptionEnum getSmsException(String code){
		if(null != code && !code.matches("^SMS:.*$")){
			code = "SMS:" + code;
		}
		return null == map.get(code) ? map.get(code):SmsExceptionEnum.DEFAULT;
	}
	
	/**
	 * @title 返回提提醒值为空
	 * @createTime 2015年10月15日 下午5:33:56
	 * @author dhc
	 */
	public static String  getExceptionMsg(String code){
		SmsExceptionEnum sms = getSmsException(code);
		return sms.getCode() + sms.getName() + sms.getDescript();
	}
	
	public MobileCodeEnum getCodeEnum() {
		if(null == codeEnum) codeEnum = MobileCodeEnum.SMS_SEND_ERROR;
		return codeEnum;
	}
	public String getCode() {
		return code;
	}

	public String getName() {
		return name;
	}
	
	public String getDescript() {
		return descript;
	}
	
	public void setDescript(String descript) {
		this.descript = descript;
	}
	
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	
	
	public String showMessage(String ... numbers){
		String str = "";
		
		if(null != number){
			for(String n : numbers){
				if(!"".equals(str)){
					str += ",";
				}
				str.concat(n);
			}
		}
		return this.getCode() + this.getName() + this.getDescript() + str;
	}
	
}
